package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.AdminOrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: sky-take-out
 * @description:
 * @author: fmp
 * @create: 2023-04-09 15:10
 * @Version 1.0
 **/
@Slf4j
@Api(tags = "订单管理")
@RestController
@RequestMapping("/admin/order")
public class AdminOrderController {
    @Resource
    private AdminOrderService adminOrderService;
    @GetMapping("/conditionSearch")
    @ApiOperation("条件分页订单查询")
    public Result selectByPage(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult result = adminOrderService.selectByPage(ordersPageQueryDTO);
        return Result.success(result);
    }
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result getStatistics(){
        OrderStatisticsVO orderStatisticsVO= adminOrderService.getStatistics();
        return Result.success(orderStatisticsVO);
    }
    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result showOrdersByOrderId(@PathVariable Long id){
        OrderVO orderVO = adminOrderService.showOrdersByOrderId(id);
        return Result.success(orderVO);
    }
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        adminOrderService.confirmOrder(ordersConfirmDTO);
        return Result.success();
    }
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        adminOrderService.rejectionOrder(ordersRejectionDTO);
        return Result.success();
    }
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancelOrder(@RequestBody OrdersCancelDTO ordersCancel){
        adminOrderService.cancelOrder(ordersCancel);
        return Result.success();
    }
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result completeOrder(@PathVariable Long id){
        adminOrderService.completeOrder(id);
        return Result.success();
    }
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result deliveryOrder(@PathVariable Long id){
        adminOrderService.deliveryOrder(id);
        return Result.success();
    }
}
